import { GCellRenderer } from "../../../../../com/mui/controls/GCellRenderer";
import { GLoadedButton } from "../../../../../com/mui/controls/GLoadedButton";
import { PetChangeModelData } from "./PetChangeModelData";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { Language } from "../../../../../extend/language/Language";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { PetConfig } from "../../../resource/PetConfig";
import { ObjCreate } from "../../common/ObjCreate";
import { PetModelPanel } from "../PetModelPanel";
import { ResFileConst } from "../../../resource/ResFileConst";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { DisplayUtil } from "../../../../common/DisplayUtil";
import { Cache } from "../../../cache/Cache";
import { EquipmentUtil } from "../../common/util/EquipmentUtil";
import { PetUtil } from "../info/PetUtil";
import { ColorConfig } from "../../../resource/ColorConfig";
import { EffectManager } from "../../../manager/EffectManager";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { LineBox } from "../../guide/LineBox";
import { PetItemInfo } from "../../../resource/info/PetItemInfo";
import { Vector } from "../../../../../__AS3__/vec/Vector";
type int = number;
//class PetChangeModelCellRenderer
    
    export  class PetChangeModelCellRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this._starData = new Vector.<GLoadedButton>();
            this.init();
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            this._vo = arg1 as PetChangeModelData;
            super.data = this._vo;
            if (typeof arg1 === "petchangemodeldata") 
            {
                if (this._vo.activate != 0) 
                {
                    this._attrBtn.filters = [];
                    this._stateTxt.htmlText = HTMLUtil.addColor(Language.getString(54937), GlobalStyle.color6);
                }
                else 
                {
                    this._attrBtn.filters = [FilterConst.colorFilter2];
                    this._stateTxt.htmlText = HTMLUtil.addColor(Language.getString(54936), GlobalStyle.color7);
                }
                this._petItemInfo = PetConfig.instance.getItemInfoByCode(this._vo.code);
                if (this._petItemInfo) 
                {
                    this._attrBtn.toolTipData = this.toolTipDatas;
                    this._nameTxt.text = this._petItemInfo.pet.name;
                    this._modelPanel.updateModelByModelId(int(this._petItemInfo.modelId));
                    this._modelPanel.isShowTurnBtn = true;
                    this._attrBtn.visible = true;
                    this.star = this._vo.attrType;
                }
                else 
                {
                    this._nameTxt.text = "";
                    this._stateTxt.htmlText = "";
                    this._modelPanel.isShowTurnBtn = false;
                    this._attrBtn.visible = false;
                    this.star = 0;
                    this._modelPanel.clean();
                }
                this._modelPanel.drawNow();
            }
            return;
        }

        public /* override */ set selected(arg1: Boolean)
        {
            super.selected = arg1;
            if (this._petItemInfo) 
            {
                this.showLineBox(arg1);
            }
            else 
            {
                this.showLineBox(false);
            }
            return;
        }

        /* internal  */init(): void
        {
            ObjCreate.createBg(0, 0, 197, 187, this);
            this._bg = new Object /* flash.display.Bitmap */();
            this._bg.x = 5;
            this._bg.y = 5;
            this.addChild(this._bg);
            this._modelPanel = new PetModelPanel();
            this._modelPanel.x = 100;
            this._modelPanel.y = 120;
            this._modelPanel.isShowTurnBtn = false;
            this.addChild(this._modelPanel);
            this._nameTxt = ObjCreate.createGTextField("", 0, 168, 197, 20, this, GlobalStyle.textFormat6);
            this._nameTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._stateTxt = ObjCreate.createGTextField("", 36, 33, 40, 20, this, GlobalStyle.textFormat6);
            this._starSp = new Object /* flash.display.Sprite */();
            ObjCreate.setObjAttri(this._starSp, 10, 10, -1, -1, this);
            this._attrBtn = ObjCreate.createGLoadedButton(ResFileConst.PetChangeModelAttrBtn, 10, 30, 25, 25, this);
            this.setStarData();
            LoaderHelp.addResCallBack(ResFileConst.PetHua, this.onLoadedHandler);
            return;
        }

        /* internal  */onLoadedHandler(): void
        {
            this._bg.bitmapData = GlobalClass.getBitmapData(ImagesConst.PetHuaBg);
            return;
        }

        /* internal  */setStarData(): void
        {
            var loc2=null;
            var loc1=0;
            while (loc1 < 4) 
            {
                loc2 = ObjCreate.createGLoadedButton(ResFileConst.GuildResourceAllocationStarBtn, 0, 0, 18, 17);
                this._starData.push(loc2);
                ++loc1;
            }
            return;
        }

        /* internal  */set star(arg1: int)
        {
            var loc2=null;
            DisplayUtil.removeAllChild(this._starSp);
            var loc1=0;
            while (loc1 < arg1) 
            {
                loc2 = this._starData[loc1] as GLoadedButton;
                ObjCreate.setObjAttri(loc2, 18 * loc1, 0, -1, -1, this._starSp);
                ++loc1;
            }
            return;
        }

        /* internal  */get toolTipDatas(): string
        {
            var loc1=null;
            var loc3=null;
            var loc2=Cache.instance.role.entityInfo.career;
            var loc4="<font color=\'#00ff00\'>";
            loc3 = EquipmentUtil.getSelfCareerAttribute(loc2, PetUtil.getAttr([this._vo.addAttr]));
            var loc5=0;
            while (loc5 < loc3.length) 
            {
                loc1 = loc3[loc5];
                loc4 = loc4 + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + loc1.name + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+" + loc1.value + "\n";
                ++loc5;
            }
            return loc4 = loc4 + "</font>" + Language.getString(54935);
        }

        /* internal  */showLineBox(arg1: Boolean): void
        {
            if (arg1) 
            {
                if (this._lineBox) 
                {
                    this._lineBox.updateLine(198, 188, [ColorConfig.instance.getItemColor(this._vo.attrType + 1).intColor], 0.5);
                }
                else 
                {
                    this._lineBox = EffectManager.getLineBox(198, 188, [ColorConfig.instance.getItemColor(this._vo.attrType + 1).intColor], 0.5, 1);
                }
                if (!this.contains(this._lineBox)) 
                {
                    this.addChild(this._lineBox);
                }
            }
            else if (this._lineBox && this.contains(this._lineBox)) 
            {
                this.removeChild(this._lineBox);
            }
            return;
        }

        /* internal */ /* var */_bg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_modelPanel: PetModelPanel;

        /* internal */ /* var */_nameTxt: GTextFiled;

        /* internal */ /* var */_lineBox: LineBox;

        /* internal */ /* var */_petItemInfo: PetItemInfo;

        /* internal */ /* var */_starData: Vector.<GLoadedButton>;

        /* internal */ /* var */_starSp: Object /* flash.display.Sprite */;

        /* internal */ /* var */_attrBtn: GLoadedButton;

        /* internal */ /* var */_vo: PetChangeModelData;

        /* internal */ /* var */_stateTxt: GTextFiled;
    }
